#include "vl_prop_reader.h"

using namespace VL;

VLPropReader::~VLPropReader() {}

void VLPropReader::readStr(std::string& str, size_t length) {
	str.clear();
	while(length > 0) {
		if(length >= _VL_PROP_READER_BUFF_SIZE) {
			this->readBuf(this->buf, _VL_PROP_READER_BUFF_SIZE - 1);
			str.append((const char *)this->buf, _VL_PROP_READER_BUFF_SIZE - 1);
			length = length - _VL_PROP_READER_BUFF_SIZE + 1;
		} else {
			this->readBuf(this->buf, length);
			str.append((const char *)this->buf, length);
			length = 0;
		}
	}
}

void VLPropReader::readStrWithSize(std::string& str) {
	auto size = this->readNumber<uint32_t>();
	if(size > 0) {
		this->readStr(str, size);
	} else {
		str.clear();
	}
}